using Godot;
using System;

public partial class MyRayCast2d : RayCast2D
{
	// Called when the node enters the scene tree for the first time.
	public override void _Ready()
	{
	}
	public override void _Process(double delta)
	{
		base._Process(delta);
		this.ForceRaycastUpdate();//强制更新射线检测,不然很有可能拿到的不是最新的结果
	}

	public override void _PhysicsProcess(double delta)
	{
		base._PhysicsProcess(delta);
		// 按下左键，拿到当前一次的射线检测结果
		if (Input.IsActionJustPressed("左"))
		{
			// 这里需要勾选 Areas 设置为启用
			if(this.IsColliding()){
				// 拿到碰撞的区域
				Area2D area = this.GetCollider() as Area2D;
				GD.Print("检测到了："+area.Name);

			}else{
				GD.Print("没有检测到");
			}
		}
	
	}
}
